package com.example.qt.ptplatform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.qt.ptplatform.entity.UserFollow;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserFollowMapper extends BaseMapper<UserFollow> {

    @Select("SELECT COUNT(*) FROM user_follow WHERE follower_id = #{followerId} AND followed_id = #{followedId}")
    int existsByFollowerAndFollowed(@Param("followerId") Integer followerId,
                                    @Param("followedId") Integer followedId);

    @Select("SELECT COUNT(*) FROM user_follow WHERE follower_id = #{userId}")
    int countByFollowerId(@Param("userId") Integer userId);

    @Select("SELECT COUNT(*) FROM user_follow WHERE followed_id = #{userId}")
    int countByFollowedId(@Param("userId") Integer userId);

    @Select("SELECT followed_id FROM user_follow WHERE follower_id = #{userId} ORDER BY create_time DESC")
    List<Integer> selectFollowingIds(@Param("userId") Integer userId);

    @Select("SELECT follower_id FROM user_follow WHERE followed_id = #{userId} ORDER BY create_time DESC")
    List<Integer> selectFollowerIds(@Param("userId") Integer userId);
}